
import Vue from 'vue'
import vuex, { Store } from 'vuex'
Vue.use(vuex)
import { nanoid } from 'nanoid'
const state = {
    sum: 0,
    presonList:[],
}

const actions = {

    oddIncrement(context,value){
        if(context.state.sum % 2 != 0){
            context.state.sum += value
        }
    },
    waitIncrement(context,value){
        setTimeout(() => {
            context.state.sum += value
        }, 2000);
    }
}

const mutations = {
    INCREMENT(state, value){
        state.sum += value
    },
    DECREMENT(state, value){
        state.sum -= value
    },
    ADD_PRESON(state,value){
        let preson = {
            name: value,
            id: nanoid()
            
        }
        state.presonList.unshift(preson)
    }
}

const getters = {
    bigNum(state){
        return state.sum * 10
    }
}

export default new vuex.Store({
    state,
    actions,
    mutations,
    getters
})